import os
from shutil import copyfile

import cv2

input_1 = '/home/yjy/dataset/IITD/IITD Palmprint V1/Segmented/Left'
out_1 = '/home/yjy/dataset/IITD-ROI-DB'


def is_left(file_name):
    return file_name.find('_l_')


def get_pid(file_name):
    return int(file_name[:3])


def get_iid(file_name):
    return int(file_name[-5:-4])


def cp(path_a, file_a, path_b, file_b=None):
    if file_b is None:
        file_b = file_a
    copyfile(os.path.join(path_a, file_a), os.path.join(path_b, file_b))


if __name__ == '__main__':
    files_1 = os.listdir(input_1)
    for ifile in files_1:
        image = cv2.imread(os.path.join(input_1, ifile), cv2.IMREAD_GRAYSCALE)
        image_resized = cv2.resize(image, dsize=(128, 128))
        newfile = '%s.JPG' % ifile[:-4]
        cv2.imwrite(os.path.join(out_1, newfile), image_resized)
